$import("com.joypard.workflow.process.ProcessDI");

K.defView("com.joypard.workflow.process.ProcessView", {

	render : function() {

		this.processGridPanel = this.createProcessGridPanel(); // 邮件日志列表面板
		this.MP = new K.Ext.MainPanel({
			items : [ this.processGridPanel ]
		});
	},

	initialize : function() {

		E.addEvents("getProcessInstanceDetails");

		E.addListener("getProcessInstanceDetailsSuccessEvent",
				this.onGetProcessInstanceDetailsSuccess, this);
	},

	createProcessGridPanel : function() {
		var me = this;
		me.expander = new Ext.ux.grid.RowExpander({
			tpl : new Ext.Template('<b>详细信息:</b><div>{content}</div>'),
			listeners : {
				expand : function(e, r, b, n) {
					if (!r.isExpand) {
						me.processGridPanel.getSelectionModel().selectRow(n);
						E.fireEvent("getProcessInstanceDetails", r, b);
						r.isExpand = true;
					}
				}
			}
		});
		var options = {
			title : "流程实例列表",
			iconCls : "p-grid",
			margins : "2 2 2 2",
			region : "center",
			viewConfig : {
				forceFit : true
			},
			plugins : me.expander,
			store : ProcessDI.createProcessStore(),
			columns : [ me.expander, {
				header : "ID",
				width : 1,
				dataIndex : "id"
			}, {
				header : "流程定义ID",
				width : 2,
				dataIndex : "processDefinitionId"
			}, {
				header : "业务标识",
				width : 1,
				dataIndex : "businessKey"
			}, {
				header : "开始时间",
				width : 2,
				dataIndex : "startTime"
			}, {
				header : "启动者ID",
				width : 2,
				dataIndex : "startUserId"
			} ],
			bbar : {
				xtype : "pagination"
			},
			listeners : {
				afterrender : function() {
					me.processGridPanel.getStore().load();
				}
			}
		};

		return new K.Ext.grid.GridPanel(options);
	},
	onGetProcessInstanceDetailsSuccess : function(content, b) {
		var record = this.processGridPanel.getSelectionModel().getSelected();
		$("div", b).html(content)
		this.expander.bodyContent[record.id] = b.innerHTML;
	}

});
